package org.example.sys

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import okhttp3.OkHttpClient
import org.example.sys.service.BookApi

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    val httpClient = OkHttpClient.Builder()
        .connectTimeout(8000, TimeUnit.SECONDS)
        .retryOnConnectionFailure(true);
    val retrofit = Retrofit.Builder()
        .baseUrl("http://192.168.1.100:555/api/v1/")
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
        .client(httpClient.build()).build().create(BookApi::class.java)

    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("org.example.sys", appContext.packageName)
    }

    @Test
    fun netWorkTest() {
        val body = retrofit.get(1, 20).execute().body()
        println(body)
    }
}